<?php

namespace Util;

class Company extends \Home {

	public static function showContactImages($contact, $type = null, $isShow =  false) {
		if($type == 2) {
			$width = 600;
			$leftHeigh = -20;
			$leftHeigh1 = -30;
		} else {
			$width = 968;
			$leftHeigh = 0;
			$leftHeigh1 = 0;
		}
		$height = 200;
		$im = imagecreatetruecolor($width, $height);
		imagefilledrectangle($im, 0, 0, $width, $height, imagecolorallocate($im, 255, 255, 255));
		$baColor = imagecolorallocate($im, 20, 20, 20);
		$contentColor = imagecolorallocate($im, 0, 0, 0);
		$font = COMMON_DIR . '/Util/Static/msyh.ttf';
		$left = 40+$leftHeigh1;
		$top = 40;
		$limit = 32;
		$leftList = $leftListBak = $left + 20;
		$fontSize = 22;
		imagettftext($im, $fontSize, 0, $left, $top, imagecolorallocate($im, 63, 131, 206), $font, $contact['Name']);
		$fontSize = 12;
		$top += 5;
		$topBak = $top;
		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, '职务：');
		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, '手机：');
		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, 'QQ：');

		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, '地址：');
		$top = $topBak;
		$leftList += 300+$leftHeigh;
		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, 'Email：');
		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, '座机：');
		imagettftext($im, $fontSize, 0, $leftList, $top = $top + $limit, $baColor, $font, '传真：');
		$myLeft = $leftListBak + 55;
		$top = $topBak;
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['Office'] ? $contact['Office'] : '-');
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['CellPhone'] ? $contact['CellPhone'] : '-');
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['QQ'] ? $contact['QQ'] : '-');
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['Address'] ? $contact['Address'] : '-');
		$top = $topBak;
		$myLeft += 300+$leftHeigh;
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['Email'] ? $contact['Email'] : '-');
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['Landline'] ? $contact['Landline'] : '-');
		imagettftext($im, $fontSize, 0, $myLeft, $top = $top + $limit, $contentColor, $font, $contact['Fax'] ? $contact['Fax'] : '-');
		// 水印
		$waterIm = imagecreatetruecolor($width, $height);
		imagefilledrectangle($waterIm, 0, 0, $width, $height, imagecolorallocate($im, 255, 255, 255));
		imagettftext($waterIm, 20, 10, 60, 120, imagecolorallocate($waterIm, 63, 131, 206), $font, '中建邺 www.tianfubiaoju.com');
		imagettftext($waterIm, 20, 10, 210, 160, imagecolorallocate($waterIm, 63, 131, 206), $font, '中建邺 www.tianfubiaoju.com');
		imagettftext($waterIm, 20, 10, 440, 180, imagecolorallocate($waterIm, 63, 131, 206), $font, '中建邺 www.tianfubiaoju.com');
		imagecopymerge($im, $waterIm, 0, 0, 0, 0, $width, $height, 15);
		header('Content-type: image/png');
		imagepng($im);
		imagedestroy($im);
	}

	/**
	 * 显示图片
	 *
	 * @param $file 图片地址
	 */
	public static function showImage($file){
		ob_clean();
		Header ('Content-type: image/jpeg');
		$im = imagecreatefromjpeg("../../" . $file);
		imagepng($im);
		imagedestroy($im);
	}

}